<template>
  <a-card>
    提现账号设置
    <a-divider type="horizontal" />
    <a-form-model :rules="validatorRules" :model="form" ref="myForm">
      <a-row>
        <a-form-model-item prop="openId">
          <label slot="label"><span style="color:red">*</span> 微信openId</label>
          <a-col :span="20">
            <a-input placeholder="点击按钮扫码获取openId" v-model="form.openId" disabled></a-input>
          </a-col>
          <a-col :span="4" style="padding: 0 10px">
            <a-button style="width: 100%;" type="orange" @click="showOpenId">点击获取</a-button>
          </a-col>
        </a-form-model-item>
      </a-row>
      <a-row>
        <a-form-model-item label="真实姓名(扫码微信号认证的实名)" prop="realname">
          <a-col :span="20">
            <a-input placeholder="请填写真实姓名" v-model="form.realname"></a-input>
          </a-col>
        </a-form-model-item>
      </a-row>
    </a-form-model>
    <a-button type="primary" @click="save" :loading="loading">保存</a-button>
    <a-button style="margin-left: 8px;" @click="closeCurrent()">关闭</a-button>
    <open-id-dialog ref="OpenIdDialog" @refresh="loadAccount"></open-id-dialog>
  </a-card>
</template>

<script>
import OpenIdDialog from '@views/account/personalSetting/OpenIdDialog'
import AgentManage from '@api/AgentManage/AgentManage'
import { getAction, postAction } from '@api/manage'

export default {
  name: 'index',
  components: { OpenIdDialog },
  inject:['closeCurrent'],
  data(){
    return {
      url:{
        account: AgentManage.account,
        updateAccountInfo: AgentManage.updateAccountInfo
      },
      form: {
        openId: '',
        realname: ''
      },
      validatorRules: {
        realname: [{ required: true, message: '请填写真实姓名!', trigger: 'change' }]
      },
      loading: false
    }
  },
  mounted() {
    this.loadAccount()
  },
  methods:{
    loadAccount() {
      getAction(this.url.account).then(res => {
        if (res.code === 200) {
          this.form = Object.assign(this.form, res.result)
        } else {
          this.$message.error(res.message)
        }
      })
    },
    showOpenId(){
      this.$refs['OpenIdDialog'].showModal()
    },
    save() {
      this.$refs.myForm.validate(valid => {
        if (valid) {
          this.loading = true
          postAction(this.url.updateAccountInfo, this.form).then(res=>{
            if (res.code === 200) {
              this.$message.success("保存成功")
              this.loadAccount()
            } else {
              this.$message.error(res.message)
            }
          }).finally(() => {
              this.loading = false
            })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>